<template>
    <div>
        <div class="marquee">
            <p>{{ scrollingText }}</p>
        </div>
        <div class="dashboard">
            <div class="card bg-blue-600">
                <div class="number">10</div>
                <div class="label">会议室总数</div>
            </div>
            <div class="card bg-green-600">
                <div class="number">5</div>
                <div class="label">当前会议室使用数</div>
            </div>
            <div class="card bg-yellow-500">
                <div class="number">5</div>
                <div class="label">今天空闲会议室数</div>
            </div>
            <div class="card bg-teal-500">
                <div class="number">355</div>
                <div class="label">今天发送会议通知数</div>
            </div>
        </div>

        <div class="schedule">
            <div class="schedule-header">
                <div class="tabs">
                    <button :class="{ active: view === 'day' }" @click="view = 'day'">日</button>
                    <button :class="{ active: view === 'week' }" @click="view = 'week'">周</button>
                    <button :class="{ active: view === 'month' }" @click="view = 'month'">月</button>
                </div>
                <span class="date">{{ currentDate }}</span>
                <button class="book-btn">会议室预定</button>
            </div>
            <div v-if="view === 'day'" class="schedule-table">
                <table>
                    <thead>
                        <tr>
                            <th>会议室</th>
                            <th v-for="hour in hours" :key="hour">{{ hour }}</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="room in meetingRooms" :key="room.name">
                            <td>{{ room.name }}</td>
                            <td v-for="hour in hours" :key="hour">
                                <div v-if="room.schedule[hour]" class="slot" :class="room.schedule[hour].status">
                                    {{ room.schedule[hour].label }}
                                </div>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div v-else class="coming-soon">该视图开发中，敬请期待~ 😎</div>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';

const scrollingText = ref(
    'IT流程管理部 曾经理 预定2025年1月3日 14:30到15:30 使用会议室A举行部门会议 已成功！'
);

const hours = [
    '08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00',
    '15:00', '16:00', '17:00', '18:00', '19:00', '20:00', '21:00', '22:00'
];

const meetingRooms = ref([
    {
        name: '会议室A',
        schedule: {
            '09:00': { label: 'IT部李经理', status: 'finished' },
            '10:00': { label: 'IT部李经理', status: 'ongoing' },
            '14:00': { label: 'E部陈主任', status: 'planned' }
        }
    },
    {
        name: '会议室B',
        schedule: {
            '08:00': { label: '营销部早会', status: 'finished' },
            '10:00': { label: 'IT部徐磊', status: 'ongoing' },
            '14:00': { label: '培训会议', status: 'planned' }
        }
    },
    {
        name: '会议室C',
        schedule: {
            '09:00': { label: '安全会议', status: 'finished' },
            '14:00': { label: 'E部徐磊', status: 'planned' },
            '15:00': { label: 'E部徐磊', status: 'planned' }
        }
    },
    {
        name: '会议室D',
        schedule: {
            '08:00': { label: '技术例会', status: 'finished' },
            '09:00': { label: '开发会议', status: 'ongoing' },
            '10:00': { label: '产品会议', status: 'planned' }
        }
    },
    {
        name: '会议室E',
        schedule: {
            '13:00': { label: '市场调研', status: 'ongoing' },
            '14:00': { label: '部门总结', status: 'planned' }
        }
    }
]);

const currentDate = ref('2025-01-15');
const view = ref('day');

onMounted(() => {
    const p = document.querySelector('.marquee p');
    let scrollAmount = window.innerWidth;

    const scroll = () => {
        scrollAmount--;
        if (scrollAmount < -p.scrollWidth) {
            scrollAmount = window.innerWidth;
        }
        p.style.transform = `translateX(${scrollAmount}px)`;
        requestAnimationFrame(scroll);
    };

    scroll();
});
</script>

<style scoped>
.marquee {
    overflow: hidden;
    white-space: nowrap;
    background-color: #007bff;
    color: white;
    padding: 10px;
    font-weight: bold;
}

.marquee p {
    display: inline-block;
    white-space: nowrap;
    will-change: transform;
    font-size: 16px;
}

.dashboard {
    display: flex;
    justify-content: space-around;
    margin: 20px 0;

}

.card {
    width: 200px;
    padding: 20px;
    color: white;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.number {
    font-size: 32px;
    font-weight: bold;
}

.label {
    font-size: 18px;
}

.schedule {
    margin: 20px;
}

.schedule-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    margin-bottom: 10px;
}

.tabs button {
    margin-right: 10px;
    padding: 6px 12px;
    border: none;
    border-radius: 4px;
    background-color: #eee;
    cursor: pointer;
}

.tabs button.active {
    background-color: #007bff;
    color: white;
}

.book-btn {
    padding: 6px 12px;
    background-color: #28a745;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.schedule-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.schedule-table th,
.schedule-table td {
    border: 1px solid #ccc;
    padding: 8px;
    text-align: center;
}

.slot {
    border-radius: 4px;
    padding: 4px;
    color: white;
    font-size: 12px;
}

.slot.finished {
    background-color: #6c757d;
}

.slot.ongoing {
    background-color: #28a745;
}

.slot.planned {
    background-color: #007bff;
}

.coming-soon {
    padding: 20px;
    color: #888;
    text-align: center;
    font-style: italic;
}
.cardbg-blue-600{
    background-color: #007bff;
}
.number{
    font-size: 32px;
    font-weight: bold;
    color: #28a745;
}
.label{
    font-size: 18px;
    color: #6c757d;
}
</style>